package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.enums.CouponCategoryEnum;
import net.xdclass.request.NewUserCouponRequest;
import net.xdclass.service.CouponService;
import net.xdclass.util.JsonData;
import org.mockito.stubbing.ValidableAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wly
 * @since 2021-09-16
 */
@Api("优惠券模块")
@RestController
@RequestMapping("/api/coupon/v1")
public class CouponController {

    @Autowired
    CouponService couponService;

    @GetMapping("page_coupon")
    public JsonData pageCouponList(@ApiParam(value = "当前页") @RequestParam(value = "page",defaultValue = "1") int page,
                                   @ApiParam(value = "每页显示多少条") @RequestParam(value = "size",defaultValue = "10")int size){
        Map<String,Object> pageMap = couponService.pageCouponActivity(page,size);
        return JsonData.buildSuccess(pageMap);
    }

    /**
     * 领取优惠券
     * @param couponId
     * @return
     */
    @GetMapping("/add/promotion/{coupon_id}")
    @ApiOperation("领取优惠券")
    public JsonData addPromotionCoupon(@ApiParam(value = "y优惠券id",required = true) @PathVariable("coupon_id")long couponId){

        return couponService.addCoupon(couponId, CouponCategoryEnum.PROMOTION);

    }

    /**
     * 新用户注册发放优惠券
     * @return
     */
    @ApiOperation("RPC-新用户注册接口")
    @PostMapping("/new_user_coupon")
    public JsonData addNewUserCoupon(@ApiParam("用户对象") @RequestBody NewUserCouponRequest newUserCouponRequest){
        return couponService.initNewUserCoupon(newUserCouponRequest);
    }



}

